//
//  UIView+Extension.swift
//  HinsLive
//
//  Created by haoxian on 2019/4/17.
//  Copyright © 2019 Hins. All rights reserved.
//

import UIKit
import Toast


extension UIView {
    var centerX: CGFloat {
        set {
            center = CGPoint(x: newValue, y: centerY)
        }
        get {
            return center.x
        }
    }
    
    var centerY: CGFloat {
        set {
            center = CGPoint(x: centerX, y: newValue)
        }
        get {
            return center.y
        }
    }
    
    var origin: CGPoint {
        set {
            frame.origin = newValue
        }
        get {
            return frame.origin
        }
    }
    
    var size: CGSize {
        set {
            frame.size = newValue
        }
        get {
            return frame.size
        }
    }
    
    var x: CGFloat {
        set {
            origin.x = newValue
        }
        get {
            return origin.x
        }
    }
    
    var y: CGFloat {
        set {
            origin.y = newValue
        }
        get {
            return origin.y
        }
    }
    
    var width: CGFloat {
        set {
            size.width = newValue
        }
        get {
            return size.width
        }
    }
    
    var height: CGFloat {
        set {
            size.height = newValue
        }
        get {
            return size.height
        }
    }
    
    var boundsCenterX: CGFloat {
        return width / 2
    }
    
    var boundsCenterY: CGFloat {
        return height / 2
    }
    
    var boundsCenter: CGPoint {
        return CGPoint(x: boundsCenterX, y: boundsCenterY)
    }
    
    var maxY: CGFloat {
        return frame.maxY
    }
    
    var maxX: CGFloat {
        return frame.maxX
    }
    
    var safeAreaInsetsWidth: CGFloat {
        return safeAreaInsets.left + safeAreaInsets.right
    }
    
    var safeAreaInsetsHeight: CGFloat {
        return safeAreaInsets.top + safeAreaInsets.bottom
    }
}

extension UIView {
    func makeCenterMsg(_ msg: String) {
        makeToast(msg, duration: 2.0, position: CSToastPositionCenter)
    }
}
